<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form>
    <%
        String s1 = request.getParameter("num1");
        if (s1 == null) s1 = "";
        String serr = "", sresult = "";
        String s2 = request.getParameter("num2");
        if (s2 == null) s2 = "";
        String sop = request.getParameter("op");
        if (sop == null) sop = "+";
        if (!s1.equals("") && !s2.equals("")) {
            int inum1 = Integer.parseInt(s1);
            int inum2 = Integer.parseInt(s2);
            try {
                switch (sop.charAt(0)) {
                    case '+':
                        sresult = inum1 + inum2 + "";
                        break;
                    case '-':
                        sresult = inum1 - inum2 + "";
                        break;
                    case '*':
                        sresult = inum1 * inum2 + "";
                        break;
                    case '/':
                        sresult = inum1 / inum2 + "";
                        break;

                }
            } catch (Exception ex) {
                serr = ex.getMessage();
            }
        }
    %>
    <%=serr%>
    <input name="num1" type="text" value="<%=s1%>">
    <select name="op">
        <option value="+" <%=(sop.equals("+") ? "selected" : "")%> >+</option>
        <option value="-" <%=(sop.equals("-") ? "selected" : "")%> >-</option>
        <option value="*" <%=(sop.equals("*") ? "selected" : "")%> >*</option>
        <option value="/" <%=(sop.equals("/") ? "selected" : "")%> >/</option>
    </select>
    <input name="num2" type="text" value="<%=s2%>">
    <input type="submit" value="=">
    <%=sresult%>
</form>
</body>
</html>
